﻿#include"game.h"


int GetMineCount(char board[Rows][Cols], int x, int y);
char mine[Rows][Cols] = { 0 };
char show[Rows][Cols] = { 0 };


void mean()
{
	printf("*********扫雷！！！*******\n");
	printf("************************\n");
	printf("*********玩吗？**********\n");
	printf("****玩扣1******不玩扣0***\n");
	printf("************************\n");
	printf("请选择:");
}



void intiboard(char board[Rows][Cols], int row, int col, char set)
{
	int i, j;
	for (i = 0; i < row; i++)
	{
		for(j = 0; j < col; j++)
		{
			board[i][j] = set;
		}
	}
}


void DisplayBoard(char board[Rows][Cols], int row, int col)
{
	int i, j;
	printf("-------------------------------\n");
	for (i = 0; i <= row; i++)
	{
		printf("%d ",i);
	}
	printf("\n");

	for (i = 1; i <= row; i++)
	{
			printf("%d ", i);
		for (j = 1; j <= col; j++)
		{
			printf("%c ",board[i][j]);
		}
		printf("\n");
	}
	
	printf("\n-------------------------------\n");
}



void setmine(char board[Rows][Cols], int row, int col)
{
	int count = EASY_COVNT;
	while (count)
	{
		int x = rand() % row + 1;
		int y = rand() % col + 1;
		if(board[x][y] != '1')
		{
			board[x][y] = '1';
		}
		count--;
	}
}



void FindMine(char mine[Rows][Cols], char show[Rows][Cols], int row, int col)
{
	int x, y;
	int win = 0;
		while (win<row*col- EASY_COVNT)
		{
			
			printf("有%d个雷，还需要排除%d个位置\n",EASY_COVNT,row * col - EASY_COVNT - win);
			printf("请输入你要排查的坐标(注意数字之间用空格隔开）：  ");
			scanf("%d%d", &x,&y);
			if(x>=1&&x<=row&&y>=1&&y<=col)
			{
				if (mine[x][y] == '1')
				{
					printf("\n\n\n丸辣，你踩到雷了！！！\n");
					
					printf("游戏结束~~~\n罚你请张磊喝杯奶茶😘\n\n\n");
					DisplayBoard(mine, Row, Col);
					printf("\n\n\n\n");
					break;
				}
				else
				{
					win++;
					show[x][y] = GetMineCount(mine, x, y) + '0';
					DisplayBoard(show, Row, Col);
				}
			}
			else
			{
				printf("你小子，不要超出输入范围,重来！！！\n");
			}

		}
		if (win == row * col - EASY_COVNT)
		{
			printf("哟，你通关了，奖励你请张磊喝杯奶茶😘");
			DisplayBoard(mine, Row, Col);
		}
		
}



int GetMineCount(char board[Rows][Cols], int x, int y)
{
	return board[x - 1][y + 1] + board[x - 1][y] + board[x - 1][y - 1] + board[x][y + 1] + board[x][y - 1] 
		+board[x + 1][y + 1] + board[x + 1][y] + board[x + 1][y - 1] - 8 * '0';
}